home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 6 / MacMania 6.toast / / Multimedia & Desktop / sk8 / SK8InJava / Code / Devices / SK8File.java < prev    next >
Encoding:
Java Source  |  1997-02-27  |  2.4 KB  |  134 lines  |  [TEXT/CWIE]

  1. /*  SK8 © 1997 Apple Computer, Inc.
  2.     This code is protected under the current SK8 License
  3.     See http://sk8.research.apple.com/ for more information
  4.     Apple Research Laboratories
  5. */
  6.  
  7.  
  8. import java.awt.*;
  9. import java.applet.Applet;
  10. import java.io.*;
  11.  
  12.  
  13. public class file extends Object
  14. {
  15.     private File     mFile;
  16.     private String     mFullName; //used when the file maybe does not exist on the disk.
  17.     
  18.     /////////////////////////////////
  19.     //
  20.     //  Constructors
  21.     //
  22.     ///////////////////////////
  23.     
  24.     public file() {
  25.         mFile = null;
  26.     }
  27.     
  28.     public file(String path) {
  29.         mFile = new File(path);
  30.     }
  31.     
  32.     
  33.     
  34.     /////////////////////////////////
  35.     //
  36.     //  data access
  37.     //
  38.     ///////////////////////////    
  39.     
  40.     public File file() {
  41.         return mFile;
  42.     }
  43.     
  44.     
  45.     /////////////////////////////////
  46.     //
  47.     //  wrapper functions
  48.     //
  49.     ///////////////////////////
  50.     
  51.     public boolean delete () {
  52.        if (mFile != null) 
  53.           return (mFile.delete());
  54.        else
  55.           return false;
  56.     }
  57.  
  58.     public boolean isdirectory () {
  59.        if (mFile != null) 
  60.           return (mFile.isDirectory());
  61.        else
  62.           return false;
  63.     }
  64.     
  65.     public boolean fileexists () {
  66.        if (mFile != null) 
  67.           return (mFile.exists());
  68.        else
  69.           return false;
  70.     }
  71.     
  72.     public list filenames (){
  73.         if ((mFile == null) || (! isdirectory()))
  74.             return null;
  75.         else {
  76.             String[] strlist = mFile.list();
  77.             list outCollection = new list();
  78.             for (int i = strlist.length - 1; i >= 0; i--){
  79.                 outCollection.push(strlist[i]);
  80.             }
  81.             return outCollection;
  82.         }
  83.     }
  84.     
  85.     
  86.     public String physicalname (){
  87.         if ((mFile == null) || (! isdirectory()))
  88.             return null;
  89.         else {
  90.             return mFile.getAbsolutePath();
  91.         }
  92.     }
  93.     public String logicalname (){
  94.         if ((mFile == null) || (! isdirectory()))
  95.             return null;
  96.         else {
  97.             return mFile.getPath();
  98.         }
  99.     }
  100.     
  101.     
  102.     public void setname (String s){
  103.         if (mFile == null)
  104.             mFullName = s;
  105.         else
  106.             mFile.renameTo(new File(s));
  107.     }
  108.     
  109.     public void createfile (){
  110.         //According to Java in a Nuthouse, files cant make themselves, 
  111.         //you need a FileOutputStream to do that.
  112.         try {
  113.             FileOutputStream fos = new FileOutputStream(mFullName);
  114.             fos.close();
  115.         } catch (Exception e){}
  116.     }
  117.             
  118.     /////////////////////////////////
  119.     //
  120.     //  utility functions
  121.     //
  122.     ///////////////////////////
  123.     
  124.     public String toString(){
  125.         if (mFile == null)
  126.             return new String("non-existant file");
  127.         else {
  128.             return mFile.toString();
  129.         }
  130.     }
  131.  
  132.  
  133. }
  134.